package edu.bw.web.role;

import cn.hutool.json.JSONUtil;
import edu.bw.common.CommonResult;
import edu.bw.dto.InsertRoleForm;
import edu.bw.service.RoleService;
import edu.bw.service.impl.RoleServiceImpl;
import edu.bw.utils.JDBCUtils;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

@WebServlet("/role/insert")
public class InsertServlet extends HttpServlet {
    RoleService roleService =new RoleServiceImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //{id: 0, roleName: "测试000", permissions: [1, 3], desc: null, changed: true}
        String reqJSON = request.getReader().readLine();
        InsertRoleForm insertRoleForm = JSONUtil.toBean(reqJSON, InsertRoleForm.class);

        Integer rows=roleService.insert(insertRoleForm);

        response.getWriter().write(JSONUtil.toJsonStr(CommonResult.ok().put("rows",rows)));





    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
